pub mod animator;
pub mod types;

pub use animator::*;
pub use types::*;

fn recursive_transition(
    start_state: f64,
    end_state: f64,
    frame_state_progress: &[f64],
) -> Vec<f64> {
    let minus = end_state - start_state;
    frame_state_progress
        .iter()
        .map(|v| start_state + minus * *v)
        .collect()
}

pub fn transition(ease: &EaseCurve, start_state: f64, end_state: f64, frame_num: f64) -> Vec<f64> {
    let frame_state_progress = get_frame_state_progress(ease, frame_num);
    recursive_transition(start_state, end_state, &frame_state_progress)
}

#[cfg(test)]
mod tests {
    use crate::{extend_curve_array_map, transition, TransitionCurveSegment};

    #[test]
    fn test_transition() {
        let ret = transition(&crate::EaseCurve::FuncHashMap("linear"), 17., 100., 50.);
        println!("{:?}", ret);
    }

    #[test]
    fn test_extend_curves() {
        let mut s = Vec::new();
        s.push(TransitionCurveSegment::OnePoint((0., -10.)));
        s.push(TransitionCurveSegment::OnePoint((-10., 0.)));
        extend_curve_array_map("test".to_string(), s);

        let ret = transition(
            &crate::EaseCurve::ArrayHashMap("test".to_string()),
            0.,
            100.,
            10.,
        );
        println!("{:?}", ret);
    }
}
